#include <iostream>
#include <memory>
#include <jsoncpp/json/json.h>
#include <sstream>

std::string Serialization()
{
    Json::Value root;
    Json::Value clild;
    clild["class"]["zwz"] = "123456";
    clild["class"]["hello"] = "world";
    root["name"] = "zwz";
    root["age"] = 19;
    root["score"].append(100);
    root["score"].append(120);
    root["class"]["zwz"] = "123456";
    root["class"]["hello"] = "world";

    Json::StreamWriterBuilder swb;
    std::unique_ptr<Json::StreamWriter> sw(swb.newStreamWriter());
    std::stringstream ss;
    sw->write(root, &ss);
    return ss.str();
}

void DeSerialization(std::string str)
{
    Json::CharReaderBuilder crb;
    std::unique_ptr<Json::CharReader> cr(crb.newCharReader());
    std::string errstr;
    Json::Value root;
    if (cr->parse(str.c_str(), str.c_str() + str.size(), &root, &errstr) == false)
    {
        std::cout << "error : " << errstr << std::endl;
    }
    std::cout << "姓名" << root["name"].asString() << " " << root["class"]["zwz"].asString()     \
    << root["score"][2]["zwz"].asString() << std::endl;

}

int main()
{
    std::string str = Serialization();
    DeSerialization(str);

    return 0;
}


